package com.ww.springboot.mybatis.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ww.springboot.mybatis.entity.PropagationEntity;
import com.ww.springboot.mybatis.mapper.PropagationMapper;
import com.ww.springboot.mybatis.service.IPropagation2Service;
import com.ww.springboot.mybatis.service.IPropagationService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-10-17 18:16
 */
@Service
@AllArgsConstructor
public class PropagationServiceImpl extends ServiceImpl<PropagationMapper, PropagationEntity> implements IPropagationService {


    private final IPropagation2Service propagation2Service;

    @Transactional
    public void test(Boolean flag1, Boolean flag11, Boolean flag2) {
        PropagationEntity propagationEntity = new PropagationEntity();
        propagationEntity.setA("A");
        propagationEntity.setB("B");
        propagationEntity.setId(IdWorker.getId());
        this.save(propagationEntity);
        try {
            propagation2Service.test(flag2);
        } catch (Exception e) {
            log.error("捕获异常!", e);
            if (!flag11) {
                throw e;
            }
        }

        if (flag1) {
            throw new RuntimeException("事务1 异常！");
        }
    }
}
